<template>
	<view class="container">
		<view class="title">绑定您的手机号</view>
		<view class="input-group uni-flex uni-flex-center">
			<view class="country-code">+86</view>
			<input type="number" v-model="phoneNumber" placeholder="请输入常用手机号" class="phone-input" />
		</view>
		<view class="btn">
			<text class="text_4" @click="getVerificationCode">获取验证码</text>
		</view>
		<view>
			<!-- 提示窗示例 -->
			<uni-popup ref="alertDialog" type="dialog">
				<uni-popup-dialog :type="msgType" cancelText="取消" confirmText="使用当前手机号" title="是否使用当前手机号"
					:content='receivedPhone' @confirm="dialogConfirm" @close="dialogClose"></uni-popup-dialog>
			</uni-popup>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phoneNumber: '',
				type: 'center',
				msgType: 'success',
				messageText: '这是一条成功提示',
				value: '',
				receivedPhone:''
			}
		},
		onLoad(options) {
			console.log('options',options);
			this.receivedPhone = options.phone ? decodeURIComponent(options.phone) : '';
			console.log('从签约页面接收的手机号：', this.receivedPhone);
		},
		mounted() {
			this.dialogToggle('info')
			// console.log('this.phoneNumber', this.phoneNumber);
		},
		methods: {
			verifyPhone(callback) {
				if (!this.phoneNumber) {
					uni.showToast({
						icon: 'none',
						title: "请输入手机号码"
					})
					return false
				}
				if (!(/^1[3-9]\d{9}$/.test(this.phoneNumber))) {
					uni.showToast({
						icon: 'none',
						title: "手机号码有误，请重填"
					})
					return false;
				}
				callback()
			},
			getVerificationCode() {
				this.verifyPhone(() => {
					// 获取验证码逻辑
					uni.navigateTo({
						url: `/pages/tabBars/bindPhone/code?phone=${this.phoneNumber}`
					})
				})
			},
			dialogToggle(type) {
				this.msgType = type
				this.$refs.alertDialog.open()
			},
			dialogConfirm() {
				uni.navigateBack({
					delta: 1
				});
			},
			dialogClose() {
				console.log('点击关闭')
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		min-height: calc(100vh - 120rpx);
		padding: 60rpx;
		background: radial-gradient(52% 101% at 16% 6%, #E2EFFF 0%, rgba(255, 255, 255, 0) 100%, rgba(255, 255, 255, 0) 100%);

		.title {
			font-weight: 600;
			font-size: 50rpx;
			color: #333333;
			margin-bottom: 80rpx;
		}

		.input-group {
			padding-bottom: 20rpx;
			border-bottom: 1px solid #E5E5E5;

			.country-code {
				color: #333;
				padding-right: 40rpx;
				margin-right: 40rpx;
				border-right: 1px solid #E5E5E5;
			}
		}

		.btn {
			width: 100%;
			height: 88rpx;
			background: #2F80ED;
			border-radius: 44rpx;
			text-align: center;
			font-size: 30rpx;
			color: #FFFFFF;
			line-height: 88rpx;
			margin: 80rpx auto 0;
		}
	}
</style>